<!--********************************************************************
* Copyright© 2000 - 2025 SuperMap Software Co.Ltd. All rights reserved.
*********************************************************************-->
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title data-i18n="resources.title_dragFeature"></title>
    <style type="text/css">
        .editPane {
            position: absolute;
            left: 50px;
            top: 10px;
            text-align: center;
            background: #FFF;
            z-index: 1000;
        }
    </style>
</head>
<body style=" margin: 0;overflow: hidden;background: #fff;width: 100%;height:100%;position: absolute;top: 0;">
<div class='panel panel-primary editPane' id='editPane' style="z-index: 99999">
    <div class='panel-heading'>
        <h5 class='panel-title text-center' data-i18n="resources.text_dragFeature"></h5>
    </div>
    <div class='panel-body' id='params'>
        <p></p>
        <div align='right' class='button-group'>
            <input type='button' id='btn1' class='btn btn-primary' data-i18n="[value]resources.text_input_value_dragFea" onclick="activateDragFeature()"/>
            <input type='button' id='btn2' class='btn btn-primary' data-i18n="[value]resources.text_input_value_notDrag" onclick="deactivateDragFeature()"/>
        </div>
    </div>
</div>

<div id="map" style="margin:0 auto;width: 100%;height: 100%"></div>
<script type="text/javascript" include="bootstrap" src="../js/include-web.js"></script>
<script type="text/javascript" exclude="iclient-classic" src="../../dist/classic/include-classic.js"></script>
<script type="text/javascript">
    var host = window.isLocal ? window.server : "https://iserver.supermap.io";
    var map, layer, vectorLayer, dragFeature;
    url = host + "/iserver/services/map-world/rest/maps/World";
    //新建矢量图层
    vectorLayer = new SuperMap.Layer.Vector("vectorlayer");
    addData();
    dragFeature = new SuperMap.Control.DragFeature(vectorLayer);
    //定义layer图层，TiledDynamicRESTLayer：分块动态 REST 图层
    layer = new SuperMap.Layer.TiledDynamicRESTLayer("World", url, {
        transparent: true,
        cacheEnabled: true
    }, {maxResolution: "auto"});
    //为图层初始化完毕添加addLayer()事件
    layer.events.on({"layerInitialized": addLayer});
    map = new SuperMap.Map("map", {
        controls: [
            new SuperMap.Control.LayerSwitcher(),
            new SuperMap.Control.ScaleLine(),
            new SuperMap.Control.Zoom(),
            new SuperMap.Control.Navigation({
                dragPanOptions: {
                    enableKinetic: true
                }
            }),
            dragFeature]
    });

    function addLayer() {
        map.addLayers([layer, vectorLayer]);
        map.setCenter(new SuperMap.LonLat(0, 0), 1);
    }

    function addData() {
        var point_data = [[-55, 34], [-90, -45], [44, -50], [100, 33], [94, 57]];
        var point_features = [];
        for (var i = 0, len = point_data.length; i < len; i++) {
            var point = new SuperMap.Geometry.Point(point_data[i][0], point_data[i][1]);
            var feature = new SuperMap.Feature.Vector(point);
            point_features.push(feature);
        }
        vectorLayer.addFeatures(point_features);

        var line_data = [[113, 19], [107, -2], [92, 13], [90, 21], [82, 12], [74, 3], [64, 22], [52, 8], [71, 0], [91, 3]];
        var points = [];
        for (var i = 0, len = line_data.length; i < len; i++) {
            var point = new SuperMap.Geometry.Point(line_data[i][0], line_data[i][1]);
            points.push(point);
        }
        var line = new SuperMap.Geometry.LineString(points);
        var line_feature = new SuperMap.Feature.Vector(line);
        vectorLayer.addFeatures([line_feature]);

        var polygon_data = [[-16, 30], [-16, 0], [50, 0], [50, 30]];
        var points = [];
        for (var i = 0, len = polygon_data.length; i < len; i++) {
            var point = new SuperMap.Geometry.Point(polygon_data[i][0], polygon_data[i][1]);
            points.push(point);
        }
        var linearRing = new SuperMap.Geometry.LinearRing(points);
        var polygon = new SuperMap.Geometry.Polygon([linearRing]);
        var polygon_feature = new SuperMap.Feature.Vector(polygon);
        vectorLayer.addFeatures([polygon_feature]);
    }

    //激活拖拽要素控件
    function activateDragFeature() {
        dragFeature.activate();
    }

    //注销拖拽要素控件
    function deactivateDragFeature() {
        dragFeature.deactivate();
    }
</script>
</body>
</html>
